<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var twoSum = function(nums, target) {
            let i = 0
            let j = nums.length-1

            while(i<j){
                const sum = nums[i]+nums[j]

                if( sum<target ){
                    i++
                }
                else if( sum>target ){
                    j--
                }
                else {
                    return [nums[i],nums[j]]
                }
            }
        };

        var nums = [10,26,30,31,47,60]
        var target = 40
        console.log(twoSum(nums, target))
    </script>
</body>
</html>